/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package drinkcounter;

import drinkcounter.web.servlet.ui.ListPartiesServlet;
import drinkcounter.web.servlet.ui.AddDrinkServlet;
import drinkcounter.web.servlet.ui.RemovePartyServlet;
import drinkcounter.web.servlet.ui.AddParticipantServlet;
import drinkcounter.web.servlet.PartyAPIServlet;
import drinkcounter.web.servlet.ui.AddPartyServlet;
import drinkcounter.web.servlet.ui.PartyServlet;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.name.Names;
import com.google.inject.servlet.GuiceServletContextListener;
import com.google.inject.servlet.ServletModule;
import com.google.inject.servlet.ServletScopes;
import com.vaadin.Application;
import drinkcounter.util.EntityManagerProvider;
import drinkcounter.util.StartPageServlet;
import drinkcounter.web.servlet.BurnAlcoholServlet;
import drinkcounter.web.vaadin.ManagerApplication;
import drinkcounter.web.vaadin.GuiceApplicationServlet;
import javax.persistence.EntityManager;

/**
 *
 * @author Toni
 */
public class DrinkCounterConfig extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new DrinkCounterModule());
    }

    class DrinkCounterModule extends ServletModule{
        public static final String STARTPAGE = "parties";
        @Override
        protected void configureServlets() {
            serve("/parties").with(ListPartiesServlet.class);
            serve("/addParty").with(AddPartyServlet.class);
            serve("/deleteParty").with(RemovePartyServlet.class);
            serve("/viewParty").with(PartyServlet.class);
            serve("/addParticipant").with(AddParticipantServlet.class);
            serve("/addDrink").with(AddDrinkServlet.class);
            serve("/API/parties/*").with(PartyAPIServlet.class);
            serve("/").with(StartPageServlet.class);
            serve("/manager").with(GuiceApplicationServlet.class);
            serve("/manager/*").with(GuiceApplicationServlet.class);
            serve("/VAADIN/*").with(GuiceApplicationServlet.class);
            serve("/internal/burnAlcohol").with(BurnAlcoholServlet.class);
            bind(EntityManager.class).toProvider(new EntityManagerProvider());
            bind(DrinkCounterService.class).to(DrinkCounterServiceImpl.class);
            bind(String.class).annotatedWith(Names.named("startpage")).toInstance(STARTPAGE);
            bind(Application.class).to(ManagerApplication.class).in(ServletScopes.SESSION);
        }
    }

}
